#include "TrueMap.h"
#include <fstream>
#include <iterator>
using namespace std;
TrueMap::TrueMap()
{
	m_nWidth=WIDTH;
	m_nHeight=HEIGHT;
	m_vData.resize(m_nHeight,vector<int>(m_nWidth,0));
}
TrueMap::~TrueMap()
{
}
void TrueMap::DrawMap(Painter*paint)
{
	for (int i=0;i<m_nHeight;i++)
	{
		for (int j=0;j<m_nWidth;j++)
		{
			paint->FillWithMapInPos(m_vData[i][j],j*ELEHEIGHT,i*ELEWIDTH,ELEHEIGHT,ELEWIDTH);
		}
	}
}
void TrueMap::LoadMapFromFile(string strFileName)
{
	ifstream inFile;
	inFile.open(strFileName.c_str());
	istream_iterator<int> strit(inFile);
 	istream_iterator<int> stritend;
	int nRol=0;
	int nRolCount=0;
	int nCol=0;
	int nColCount=0;
	vector<int> colmap;
	vector<int>::iterator it;
	copy(strit,stritend,std::inserter(colmap,colmap.begin()));
	for (it=colmap.begin();it!=colmap.end();it++)
	{			
		int nTmp=*it;
		nRol=nRolCount/m_nWidth;
		nCol=nColCount%m_nWidth;
		nRolCount++;
		nColCount++;
		m_vData[nRol][nCol]=*it;
	}
	inFile.close();
}
